package com.tjbank.cssys.web.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.tjbank.cssys.domain.CkLog;
import com.tjbank.cssys.web.service.CkCreditOutCompanyDataRelationService;
import com.tjbank.cssys.web.service.CkLogService;
import com.tjbank.cssys.web.util.CommonResult;
import com.tjbank.cssys.web.util.GetUserCodeFromToken;
import com.tjbank.cssys.web.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;
import java.util.UUID;

/**
 * 委外公司对账佣金情况查询
 */
@RestController
@RequestMapping("/company/commission")
public class CkCreditOutCompanyDataRelationController {

    @Autowired
    private CkCreditOutCompanyDataRelationService ckCreditOutCompanyDataRelationService;

    @Autowired
    private CkLogService ckLogService;

    /**
     * 委外公司对账佣金 列表查询
     * @param params
     * @param request
     * @return
     */
    @PostMapping("/list")
    public CommonResult getList(@RequestBody Map<String, String> params, HttpServletRequest request){
        CommonResult result = null;
        String userCode = null;

        CkLog ckLog = new CkLog();
        ckLog.setLogId(UUID.randomUUID().toString());
        ckLog.setLogName(UUID.randomUUID().toString());
        Date date = new Date();
        ckLog.setTimes(new Date(date.getTime()));
        ckLog.setParams(JSON.toJSONString(params));
        ckLog.setOperationType("委外公司对账佣金 列表");
        try {
            userCode = GetUserCodeFromToken.getUserCode(request);
            ckLog.setUserId(userCode);
            PageInfo pageInfo = ckCreditOutCompanyDataRelationService.listData(request,params);
            result = CommonResult.success(pageInfo,"查询成功！");
            ckLog.setResult(String.valueOf(ResultCode.SUCCESS.getCode()));
        }catch (Exception e) {
            ckLog.setResult(String.valueOf(ResultCode.FAILED.getCode()));
            result = CommonResult.failed("查询失败");
        } finally {
            ckLogService.addInsert(ckLog);
            return result;
        }

    }



}
